$(function () {
	var gridSetting={
			url: '../repository/process-definitions',
			colModel: [			
				{ label: 'id', name: 'id', index: 'id', width: 50, key: true },
				{ label: '名称', name: 'name', index: 'name', width: 80 }, 			
				{ label: '版本', name: 'version', index: 'version', width: 80 }, 			
				{ label: 'key', name: 'key', index: 'key', width: 80 }, 			
				{ label: '描述', name: 'description', index: 'description', width: 80 }, 			
				{ label: '部署id', name: 'deploymentId', index: 'deploymentId', width: 80 },			
				{ label: '流程图', name: 'diagramResource', index: 'diagramResource', width: 80/*,formatter:function(cellvalue, options, rowObject){
					var temp = "<img src='"+cellvalue+"'/>";
					return temp;
				}*/ },			
				{ label: '资源', name: 'resource', index: 'resource', width: 80,formatter:function(cellvalue, options, rowObject){
					var temp = "<a href='"+cellvalue+"' target='_blank'>下载 </a>";
					return temp;
				} }			
	        ],
	}
	gridSetting=$.extend(true,baseJqGridSetting,gridSetting);
    $("#jqGrid").jqGrid(gridSetting);
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		bpmProcessDefinitions: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		startProcess: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			var startProcessParam={};
			startProcessParam.processDefinitionId=id;
			startProcessParam.businessKey=uuid();
			startProcessParam.variables=[];
			var variablesParam={};
			variablesParam.name="myVar";
			variablesParam.value="This is a variable";
			startProcessParam.variables.push(variablesParam);
			$.ajax({
				type: "POST",
			    url: "../runtime/process-instances",
			    data: JSON.stringify(startProcessParam),
			    contentType: "application/json",
			    success: function(r){
			    	alert('操作成功', function(index){
						$("#jqGrid").trigger("reloadGrid");
					});
				}
			});
		},
		showModel: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
		/*	var url='../modeler.html?modelId='+id;
			window.location.href=url;*/
			parent.layer.open({
				type:2,
				offset: '50px',
				skin: 'layui-layer-molv',
				title: "查看流程状态",
				area: ['1200px', '600px'],
				shade: 0,
				shadeClose: false,
				content: ['diagram-viewer/index.html?processDefinitionId='+id+'&processInstanceId=', 'no'],
			});
		},
		flowNodeSet() {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			
	        var url="../bpm/bpmProcessDefinitionsNode.html?processDefinitionId="+id;
	        //弹框层
	        layer.open({
	            scrollbar: false,
	            type: 2,
	            title : ["流程节点设置" , true],
	            area: ['80%', '80%'], //宽高
	            content: [url,'no'],
	            shadeClose : false,
	        });
	    },
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});